import os
import sys
import logging
import onnxruntime

class ONNXBase(object):
    def __init__(self, model_dir=None) -> None:
        logging.debug(f"ONNXBase init.")
        self.model_dir = model_dir

        device = onnxruntime.get_device()
        self.providers = onnxruntime.get_available_providers()
        logging.info(f"device:{device} providers:{self.providers}")

    def __del__(self):
        logging.debug(f"ONNXBase destruct.")

    def _get_onnx_input_name(self, sess):
        inputs_tensor = sess.get_inputs()
        inputs_name = [inputs_tensor[i].name for i in range(len(inputs_tensor))]
        for i, name in enumerate(inputs_name):
            logging.debug(f"input[{i}] name:{name}")

        return inputs_name

    def _get_onnx_output_name(self, sess):
        outputs_tensor = sess.get_outputs()
        outputs_name = [outputs_tensor[i].name for i in range(len(outputs_tensor))]
        for i, name in enumerate(outputs_name):
            logging.debug(f"output[{i}] name:{name}")

        return outputs_name

    def _preproc(self, data):
        pass